#include "stdafx.h"
#include "fault_oneround.h"
#include "keyschedule.h"
#include "addroundkey.h"
#include "sboxlayer.h"
#include "fault_insert.h"
#include "player.h"


void fault_oneround( const unsigned char in_foneround[] , const unsigned char in_froundkey[] , unsigned char fault[] , const int fround , unsigned char out_foneround[] ,unsigned char out_froundkey[] )
{
	unsigned char out_fresult[16] ;
	KeySchedule( in_froundkey , fround , out_froundkey ) ;
	unsigned char foneroundxorkey[64] ;
	for ( int i = 0 ; i <=63 ; i++ )
	{
		foneroundxorkey[i] = in_froundkey[i+16] ;
	}
	unsigned char in_fsboxstate[64] ;
	unsigned char in_fplayerstate[64] ;
	AddRoundKey( in_foneround , foneroundxorkey , in_fsboxstate ) ;
	sBoxLayer( in_fsboxstate , in_fplayerstate ) ;
	fault_insert( fround , fault , in_fplayerstate ) ;
	pLayer( in_fplayerstate , out_foneround ) ;
//  	for ( int i = 0 ; i <= 63 ; i++ )
//  	{
//  		printf( "%x" , out_foneround[i] ) ;
//  	}
// 	printf( "\n" ) ;
	for ( int i = 0 ; i <= 15 ; i++ )
	{
		out_fresult[i] = (out_foneround[4*i+3]<<3)|(out_foneround[4*i+2]<<2)|(out_foneround[4*i+1]<<1)|(out_foneround[4*i]) ;
	}
//  	for ( int i = 15 ; i >= 0 ; i-- )
//  	{
//  		printf( "%x" , out_fresult[i] ) ;
//  	}
// 	printf( "\n" ) ;
}